/*** Class Name: WorkflowSummaryController
**** Author: Accenture
**** Date: 5-May-2011
**** Requirement/Project Name: iFulfill
**** Requirement Description: TO Display the Workflow Summary
**/
public with sharing class WorkflowSummaryController {
    
   public Workflow_definition__c wfd;
   public List<Wokflow_Steps__c> wfSteps;
   Public Id wfId{get;set;}
   private Map<ID,List<Workflow_Activities__c>> StepActMAP =new Map<ID,List<Workflow_Activities__c>>();
       
      public WorkflowSummaryController(ApexPages.StandardController controller) {
        wfd = (Workflow_definition__c)controller.getRecord();
        wfId = wfd.id;
      }
      
      public list<Workflow_Stage__c> getWflowFunc(){
         //return [select name, id , sequence__c, Target_days__C from Workflow_Stage__c where Workflow_Code__c =:wfId order by sequence__c asc]; 
         return [select name, id , sequence__c from Workflow_Stage__c where Workflow_Code__c =:wfId order by sequence__c asc]; 

      }
      
      public list<WF_Assignment_Group__c> getasgnGroups(){
       return [select name,Workflow_Function__c from WF_Assignment_Group__c where Workflow_Function__r.Workflow_Code__c =: wfd.id ];
      }
      
      Class wrapperOut{
          Public Wokflow_Steps__c Step{get;set;}
          Public List<Workflow_Activities__c> Act{get;set;} 
          Public wrapperOut(){
            if(step==null){step= new Wokflow_Steps__c();}
            if(Act==null){Act= new List<Workflow_Activities__c>();}            
          }
      }
   
      public list<wrapperOut> getWFDetails(){
         list<wrapperOut> wrapout = new list<wrapperOut>(); 
         wfSteps = [select id,Wokflow_Stage_Name__c,name,sequence__C,Dashboard_Function__c,Step__r.name,Target_Days__c,Default_Group__c from Wokflow_Steps__c where Wokflow_Stage_Name__r.Workflow_Code__c =: wfd.id order by sequence__c asc];
         for(Workflow_Activities__c wfAct : [select name,Step_Name__c,Required__c,Status__c from Workflow_Activities__c where Step_Name__c in : wfSteps]){
                if(StepActMAP.containsKey(wfAct.Step_Name__c)){
                    StepActMAP.get(wfAct.Step_Name__c).add(wfAct);//adds activities for this step to the activity list in the map    
                }else{
                    StepActMAP.put(wfAct.Step_Name__c,new List<Workflow_Activities__c>{wfAct});//adds new activity list for this step to the map    
                }   
         }         
         for(Wokflow_Steps__c WFS :wfSteps){
                wrapperOut tmpwrapper = new wrapperOut();               
                tmpwrapper.Step = WFS; 
                List<Workflow_Activities__c> actList =new List<Workflow_Activities__c>();                 
                if(StepActMAP.containsKey(WFS.id)){
                    for(Workflow_Activities__c WFAct : StepActMAP.get(WFS.id)){
                        actList.add(WFAct);
                    }
                }
                tmpwrapper.Act = actList;                
                wrapout.add(tmpwrapper);             
         }
   
        return wrapout;
    }
    
     
       
}